package com.emm.yixun.openapi.dto.exception;

import com.emm.yixun.common.exception.XFUNExceptionCode;

public class XFUNCheckedException extends RuntimeException {

	private static final long serialVersionUID = 1720755012635650684L;
	private String code;
	private String outMsg;;
	private String inMsg;;

	public String getOutMsg(){
		if(outMsg != null){
			return inMsg;
		}
		XFUNExceptionCode mcode = XFUNExceptionCode.getByCode(code);
		if(mcode!=null){
			return mcode.getDesout();
		}
		return getMessage();
	}
	
	public String getInMsg(){
		if(inMsg != null){
			return inMsg;
		}
		XFUNExceptionCode mcode = XFUNExceptionCode.getByCode(code);
		if(mcode!=null){
			return mcode.getDesin();
		}
		return getMessage();
	}
	
	public XFUNCheckedException() {
		super();
	}

	public XFUNCheckedException(Throwable e) {
		super(e);
	}

	public XFUNCheckedException(String errorCode) {
		super();
		this.code = errorCode;
	}

	public XFUNCheckedException(XFUNExceptionCode mcode) {
		super();
		this.code = mcode.getCode();
	}
	public XFUNCheckedException(XFUNExceptionCode mcode, Throwable e) {
		super(mcode.getDesout(),e);
		this.code = mcode.getCode();
	}
	
	public XFUNCheckedException(String code, Throwable e) {
		super(XFUNExceptionCode.getOutMsg(code),e);
		this.code = code;
	}

	public XFUNCheckedException(String code, String outMsg) {
		super(outMsg);
		this.outMsg = outMsg;
		this.code = code;
	}

	public XFUNCheckedException(String code, String outMsg, Throwable e) {
		super(outMsg, e);
		this.outMsg = outMsg;
		this.code = code;
	}
	public XFUNCheckedException(String code, String outMsg,String inMsg, Throwable e) {
		super(outMsg, e);
		this.code = code;
		this.outMsg = outMsg;
		this.inMsg = inMsg;
		this.code = code;
	}
	
	public String getCode() {
		//需要登陆的接口统一封装返回统一编码
		if(code.endsWith("30001")){
			return XFUNExceptionCode.USER_UNLOGIN.getCode();
		}
		return code;
	}

}
